/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "cmsis_os.h"
/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
typedef struct {
  float aht_temp;    // AHT20温度
  float aht_hum;     // AHT20湿度
  float ntc_temp;    // NTC温度
  float temp_diff;   // 新增：温度差值（AHT20 - NTC）
} SensorData;
typedef struct {
  SensorData sensor_data;  // 传感器原始数据+差值
  char log_str[120];       // 格式化后的字符串（可选，也可在发送任务中格式化）
} UartMsg;
/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
extern SensorData g_sensor_data;               // 传感器数据结构体实例
extern osEventFlagsId_t TempEventHandle;       // 事件标志组句柄
extern osMutexId_t DataMutexHandle;            // 数据保护互斥锁句柄
extern osMessageQueueId_t UartMsgQueueHandle;
/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define LED_Pin GPIO_PIN_0
#define LED_GPIO_Port GPIOB

/* USER CODE BEGIN Private defines */
#define NTC_B_VALUE 3950    // NTC的B系数（如3950、3000等，看 datasheet）
#define NTC_R_REF 10000     // 分压电阻阻值（单位：Ω，如10KΩ）
#define NTC_T_REF 298.15    // 参考温度（25℃对应的开尔文温度：25+273.15=298.15K）

#define EVENT_AHT_DONE  0x01  // AHT20读取完成标志（二进制0001）
#define EVENT_NTC_DONE  0x02  // NTC读取完成标志（二进制0010）
#define UART_QUEUE_LENGTH 5    // 队列最多缓存5条数据
#define UART_QUEUE_ITEM_SIZE sizeof(UartMsg)  // 每个队列项大小

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
